//http://code.google.com/codejam/contest/2334486/dashboard#s=p1
//Ac
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/*
  4
B 5'11" 6'2"
G 5'11" 6'2"
B 3'4" 3'4"
G 1'1" 1'0"
*/

/*
  Case #1: 5'11" to 6'7"
  Case #2: 5'6" to 6'2"
  Case #3: 3'3" to 3'10"
  Case #4: 0'6" to 1'2"
 */
#define FILEIO

int BabyHeight_main(int argc,char **argv) 
{ 

#ifdef FILEIO
  freopen("BabyHeight_in.txt","r",stdin); 
  freopen("BabyHeight_out.txt","w",stdout); 
#endif

  int T;
  char gender;
  int mhFoot;
  int mhInch;

  int fhFoot;
  int fhInch;

  char tChar;

  float middleNumber=0;
  int i,j;
  
  scanf("%d",&T);
  scanf("%c",&tChar);

  for(i = 1;i <= T;i++) 
    {
      scanf("%c",&gender);

      scanf("%d",&mhFoot);
	  scanf("%c",&tChar);
      scanf("%d",&mhInch);
	  scanf("%c",&tChar);
      scanf("%d",&fhFoot);
	  scanf("%c",&tChar);
      scanf("%d",&fhInch);
	  scanf("%c",&tChar);

      scanf("%c",&tChar);
      //scanf("%c",&tChar);

      switch(gender)
        {
        case 'B':
          middleNumber = (float)((mhFoot*12 + mhInch) + (fhFoot*12 + fhInch)  + 5)/(float)2;
          break;
        case 'G':
          middleNumber = (float)((mhFoot*12 + mhInch) + (fhFoot*12 + fhInch) - 5)/(float)2;          
          break;
        }

      if(middleNumber == (int)middleNumber)  
        {
          j = (int)middleNumber;

          printf("Case #%d: %d'%d\" to %d'%d\"\n",i,(j - 4)/12,(j - 4)%12,(j + 4)/12,(j + 4)%12);
        }
      else
        {
          j = (int)middleNumber;
          printf("Case #%d: %d'%d\" to %d'%d\"\n",i,(j - 3)/12,(j - 3)%12,(j + 4)/12,(j + 4)%12);
        }
    }

#ifdef FILEIO
  fclose(stdin);
  fclose(stdout);
#endif
  
  return 0; 
} 
